Gradle >=4.6: using java-library & java plugins simultaneously in multi-module build
NickName:gavenkoa Ask DateTime:2019-02-11T04:26:41

Gradle >=4.6: using java-library & java plugins simultaneously in multi-module build

Since Gradle 4.6:

new configurations were added: api (only in java-library plugin) & implementation (defined by both).

In multi-module project I have several "core" modules that act as internal libraries and sometimes need to pass exposed compile time dependencies via api configuration.

Previously we applied java plugin recursively:

subprojects {
    apply plugin: 'java'
}

To be purist we can apply java-library plugin to "library" modules and java plugin to "end-application" modules.

What if we just put:

subprojects {
    apply plugin: 'java'
    apply plugin: 'java-library'
}

NOTE With proper naming schema (we don't have one) it is possible to do selectively:

subprojects {
    if (project.name.startsWith('lib-')) {
        apply plugin: 'java-library'
    } else {
        apply plugin: 'java'
    }
}

Copyright Notice:Content Author:「gavenkoa」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/54620695/gradle-4-6-using-java-library-java-plugins-simultaneously-in-multi-module-b

More about “Gradle >=4.6: using java-library & java plugins simultaneously in multi-module build” related questions

Gradle implementation not importing gradle module into gradle project

I have created two gradle, Let's say Libary-Project and TestProject in the same eclipse workspace folder. Below are the build.gradle and settings.gradle for Library Project. Library Project build....

Show Detail

Gradle multiple versions OF GRADLE

For the sake of clarity: this is NOT about multiple versions of dependencies, it's about multiple versions of Gradle's own jars. I thought this might have the answer... but there aren't any! This...

Show Detail

Gradle not reading gradle.properties

Gradle will not read gradle.properties. I guess I might have screwed up some install by running it as sudo. I execute ./gradlew createDb --stacktrace --debug 20:56:58.422 [INFO] [org.gradle.

Show Detail

gradle - custom build.gradle AND settings.gradle

folks, is anyone aware how to use gradle to run with a custom build.gradle AND settings.gradle - i.e both together? I think that I can have a custom build.gradle file (-b flag) - but then this i...

Show Detail

Gradle properties not being read from ~/.gradle/gradle.properties

I have a similar problem as detailed here: http://gradle.1045684.n5.nabble.com/gradle-gradle-properties-not-being-read-td4372872.html In fact, it's the exact same problem - except that the solutio...

Show Detail

Gradle lock exception: Gradle in use by another Gradle instance

I am having a Gradle weird issue which does not seem to be related with me code. When I checked Jenkins, the build was broken with this exception: Caused by: org.gradle.cache.internal.

Show Detail

Gradle Error: Not able to use gradle

Installed gradle version 2.10 from using HomeBrew and the Offical Zip file. Trying to run command: gradle --version (or any other command) Getting error: FAILURE: Build failed with an exception....

Show Detail

Gradle ignoring gradle.properties

I'm just starting out with Gradle and am almost certainly missing something obvious. My system has Java 7 installed as the default but I want all my Gradle projects to be using Java 8 by default. S...

Show Detail

Difference between Settings gradle, property gradle and build gradle

I am new to java and I was going through this article on medium Here author wrote something like this to explain project file The settings.gradle file contains a list of your modules and projec...

Show Detail

gradle - Failed to run Gradle Worker Daemon

gradle build is successful when GRADLE_USER_HOME is not set. But build is failing with "Failed run Gradle Worker Daemon" when the variable GRADLE_USER_HOME is set to a different location....

Show Detail